// 引入vuex的API
import {createStore} from "vuex"

// 引入模块
import moduleA from "./Modules/moduleA"
import moduleB from "./Modules/moduleB"

// 
export default createStore({
    modules:{
        a:moduleA,
        b:moduleB,
    },
    state:{
        count:100,
        test:"hello world",
    },

    getters:{
        countAddFive:(state)=>{
            return state.count+5
        },
        countAddFiveTem:(state,getters) =>{
            return getters.countAddFive + 10
        },
    },
    mutations:{
        add(state){
            state.count++
        },
        addPlayload(state,playload){
            state.count += playload.num
        }
    },
    actions:{
        // addAction(contest){
        //     contest.commit('add')
        // },
        addAction({commit}){
            commit('add')
        },
        asyncAddAction({ commit }){
            setTimeout(()=>{
                commit('add')
            },1000)
        },
        asyncAddPloyloadAction({ commit }, playload){
            setTimeout(()=>{
                commit('addPlayload',playload)
            },1000)
        }
    }
})